package com.lxyk.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.lxyk.mapper.CustomerMapper;
import com.lxyk.pojo.Customer;
import com.lxyk.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Service
@Slf4j
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer>implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public PageInfo<Customer> listCust(Customer customer, Integer pageNum, Integer pageSize) {
        List<Customer> customers = customerMapper.listCustomer(customer);
        return new PageInfo<>(customers);
    }

    @Override
    public int saveCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    @Override
    public List<Customer> searchCustomer(String custName,String custMobile) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("cust_name",custName).eq("cust_mobile",custMobile);
        return customerMapper.selectList(qw);
    }


    @Override
    public int deleteCustomerById(Integer cid) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("cid",cid);
        return customerMapper.delete(qw);
    }

    @Override
    public Customer getCustomerById(Integer cid) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("cid",cid);
        return customerMapper.selectOne(qw);
    }

    @Override
    public int updateCustomer(Customer customer) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        // update....where cid = ?
        qw.eq("cid",customer.getCid());
        return customerMapper.update(customer,qw);
    }


}
